package com.swing.border;


import com.swing.border.af.swing.layout.AfYLayout;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import java.awt.*;


public class MyFrame extends JFrame
{

	public MyFrame(String title)
	{
		super(title);
		
		// 创建一个Box，并设置为顶层容器 （取代原有的顶层容器)
		JPanel root = new JPanel();
		this.setContentPane(root);
		root.setLayout(new AfYLayout(4));
		
		// 也可以给  JPanel 设置一个边框
//		Border border = BorderFactory.createLineBorder(Color. BLUE, 4);
//		root.setBorder(border);
		
		JLabel a1 = new ColorfulLabel("1", new Color(0xC0FF3E));
		root.add(a1, "60px");
				
		JLabel a2 = new ColorfulLabel("2", new Color(0xEEEE00));
		root.add(a2, "60px");
		// 给a2添加边框
		Border border2 = new LineBorder(Color.BLUE, 4);
		a2.setBorder(border2);
		
		JLabel a3 = new ColorfulLabel("3", new Color(0x98FB98));
		root.add(a3, "60px");
		// 给a3添加边框,BorderFactory用来生成Border的工厂。
		Border border3 = BorderFactory.createLineBorder(Color.BLUE, 4);
		a3.setBorder(border3);	
		
		
		
	}
	
	private static class ColorfulLabel extends JLabel
	{
		public ColorfulLabel(String text, Color bgColor)
		{
			super(text);
			
			setOpaque(true);
			setBackground(bgColor);
			//setPreferredSize(new Dimension(60,30));
			setHorizontalAlignment(SwingConstants.CENTER);
			setFont(new Font("宋体", Font.PLAIN, 16));
		}
	}	
	
	
}
